package br.com.onlinebidding.managedbean;

import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import br.com.onlinebidding.dao.UserDAO;
import br.com.onlinebidding.entity.User;

@SessionScoped
@ManagedBean
public class UserMB {
	
	private User user;
	private List<User> users;
	private UserDAO userDAO;
	
	public User getUser() {
		if (user == null) {
			user = new User();
		}
		return user;
	}
	
	public void User(User user) {
		this.user = user;
	}
	public void createUser() {
		try {
			userDAO.insert(user);
		
			loadUser();
			resetUser();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	private void loadUser() {
		users = userDAO.getAll();
	}

	public void resetUser() {
		user = new User();
	}

}
